package com.example.chartroom1.controller;

import com.example.chartroom1.mapper.FriendMapper;
import com.example.chartroom1.model.Friend;
import com.example.chartroom1.model.User;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/friend")
public class FriendController {
    @Resource
    private FriendMapper friendMapper;
    @RequestMapping("/friendList")
    public Object getFriendList(HttpServletRequest request){
        HttpSession session = request.getSession(false);
        if (session == null) {
            return new ArrayList<Friend>();
        }
        User user = (User) session.getAttribute("user");
        if(user == null) {
            return new ArrayList<Friend>();
        }

        List<Friend> res = friendMapper.selectFriendList(user.getUserId());
        return res;
    }
}
